home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * @@@BUILDINFO@@@ 33scriptsPane.jsx 1.0.0.61 06-Mar-2005
- * Copyright 2005 Adobe Systems Incorporated
- * All Rights Reserved.
- *
- * NOTICE: All information contained herein is, and remains the property of
- * Adobe Systems Incorporated and its suppliers, if any. The intellectual
- * and technical concepts contained herein are proprietary to Adobe Systems
- * Incorporated and its suppliers and may be covered by U.S. and Foreign
- * Patents,patents in process,and are protected by trade secret or copyright
- * law. Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained from
- * Adobe Systems Incorporated.
- **************************************************************************/
-
- // Code to add to the Scripts pane
- // The output field of the scripts pane is a list box. The array scriptIDs
- // takes a list of all script IDs. This list is used during Document.onSave()
- // to determine if a document belongs to a target app and whether that app
- // should receive a PutScript message.
-
- // Get the script IDs and populate the Scripts pane. Each line contains
- // two words. The first, is the display name, while the second word is the
- // script ID. The script ID must be a path name if it starts with '/' or '~'. If
- // it starts with anything else but a '(' (which is reserved for new scripts),
- // it is app specific, and the app will have to supply the script on request.
- // Application-supplied script IDs should be system unique.
-
- // The "info" property is an object with script IDs as property names. Each
- // object has the properties displayName, scriptID, status and readOnly. If a script
- // is not executable, the status is "noexec". The object is also attached to
- // the list item.
-
- window.scripts.info = {};
-
- window.scripts.getScripts = function()
- {
- var bt = BridgeTalk.create (currentDebugger.target, "GetScripts");
- bt.headers.Engine = currentDebugger.engine;
- bt.onOwnResult = function (bt)
- {
- var target = this.target.replace ("#estk", "");
- // clear all lists
- window.scripts.output.removeAll();
- window.scripts.info = {};
- var reply = bt.splitBody();
- for (var i = 0; i < reply.length; i++)
- {
- // if we have an empty line, this is the separator between scripts and additional info
- if (reply [i].length == 0)
- break;
- // fill in what we have got
- var displayName = reply [i][0];
- var scriptID = reply [i][1];
- var status = reply [i][2];
- var readOnly = reply [i][3];
- if (!status)
- status = "exec";
- // backwards compatibility
- if (status == "active")
- status = "exec";
- // do we have both?
- if (displayName.length && scriptID.length)
- {
- // Remove .LNK from a display name in case installers failed
- if (displayName.substr (displayName.length-4) == ".LNK")
- displayName = displayName.substr (0, displayName.length-4);
- var item = window.scripts.output.add ("item", displayName);
- item.info = { displayName:displayName, scriptID:scriptID,
- status:status, readOnly:(readOnly == true) };
- window.scripts.info [scriptID] = item.info;
- // Include path fix: If the 1st script ID is a valid file,
- // set the include path to the parent of that file
- if (i == 0 && (scriptID [0] == '/' || scriptID [0] == '~'))
- {
- var f = new File (scriptID);
- if (f.exists)
- app.includePath = f.parent.absoluteURI;
- }
- }
- }
- // do we have extra info?
- if (++i < reply.length && reply[i].length && reply [i][0].length)
- {
- // 1st extra line (V48+): the include path
- app.includePath = reply [i][0];
- }
- // If there are any entries, add a blank line so we can deselect/reselect entries
- if (window.scripts.output.items.length)
- window.scripts.output.add ("item", "");
- }
- bt.safeSend();
- }
-
- // Deselect the current selection. Called when a document is closed.
-
- window.scripts.deselect = function()
- {
- this.output.selection = null;
- }
-
- // Load a script from file and bring that doc to the front.
-
- window.scripts.loadFile = function (scriptID)
- {
- var doc;
- var file = new File (scriptID);
- // Try to find an existing doc
- for (var i = 0; i < documents.length; i++)
- {
- doc = documents [i];
- if (doc.scriptID == scriptID)
- {
- // the doc is already present, so reload
- doc.load (new File (scriptID));
- window.breakpoints.update();
- document = doc;
- return doc;
- }
- }
- // not found: create a new document
- doc = Document.create (file);
- if (doc)
- doc.status = "exec";
- return doc;
- }
-
- // Get a script from the target app.
-
- window.scripts.loadScript = function (scriptID, title)
- {
- if (scriptID [0] == '(')
- return;
- else if (scriptID [0] == '/' || scriptID [0] == '~')
- {
- this.loadFile (scriptID);
- return;
- }
- var bt = BridgeTalk.create (currentDebugger.target, "GetScript");
- bt.headers.Engine = currentDebugger.engine;
- bt.headers.ScriptID = scriptID;
- // attach additional data for onResult()
- bt.engine = currentDebugger.engine;
- bt.title = title;
- bt.dbg = currentDebugger; // in case we switched away before the reply comes in
-
- bt.onOwnResult = function (bt)
- {
- // Try to find the script if already loaded
- var target = bt.sender.replace ("#estk", "");
- // add in the BT name again
- var scriptID = this.headers.ScriptID;
- var doc = documents.find (scriptID);
- if (!doc)
- {
- // new doc: try to find the title in the list of scripts
- if (!this.title)
- {
- var info = window.scripts.info [scriptID];
- if (info)
- this.title = info.displayName;
- else
- // fallback: use the display name as title
- this.title = BridgeTalk.getTargetDisplayName (target);
- }
- doc = Document.create (this.title, bt.body, scriptID);
- }
- else
- {
- // make sure that the text is displayed.
- doc.text = bt.body;
- window.breakpoints.update();
- }
- // set target and engine
- var info = window.scripts.info [scriptID];
- doc.target = target;
- doc.engine = this.engine;
- doc.status = info ? info.status : "exec";
- doc.readOnly = info ? info.readOnly : true;
- // To be on the safe side, mark the script received as read only
- // if there is no script ID.
- if (!scriptID.length)
- doc.readOnly = true;
-
- app.toFront();
- // this may be a reload of a doc
- if (this.dbg && (!this.dbg.document || this.dbg.document.scriptID == doc.scriptID))
- this.dbg.setDocument (doc);
- // reflect the script state etc
- debugMenu.reflectState();
- }
- // Error: tell the user
- bt.onOwnError = function (bt)
- {
- if (this.dbg)
- this.dbg.stop();
- errorBox ("$$$/ESToolkit/Alerts/CannotLoadScript=Cannot load script from target %1!",
- BridgeTalk.getTargetDisplayName (this.target));
- }
- bt.safeSend();
- }
-
- // Store the script into the target if appropriate. Return true if a PutScript
- // operation was initiated.
-
- window.scripts.storeScript = function (doc)
- {
- var scriptID = doc.scriptID;
- if (scriptID != '(' && scriptID != '/' && scriptID != '~')
- {
- var bt = BridgeTalk.create (currentDebugger.target, "PutScript");
- bt.headers.Engine = currentDebugger.engine;
- bt.headers.ScriptID = scriptID;
- bt.body = doc.text;
- bt.docTitle = doc.title;
- // use onResult - the result is debugger independent
- bt.onResult = function (bt)
- {
- var doc = documents.find (this.headers.ScriptID);
- if (doc)
- doc.setSavedState();
- // the scripts pane may have changed due to the save operation
- window.scripts.getScripts();
- this.destroy();
- }
- // use onError - the error is debugger independent
- bt.onError = function (bt)
- {
- errorBox (localize ("$$$/CT/ExtendScript/Errors/Err46=%1 is read only", this.docTitle));
- this.destroy();
- }
- bt.safeSend();
- return true;
- }
- else
- // traditional disk save
- return false;
- }
-
- // The callback for the output list box is activated when the user
- // selects a different script. The code tries to find the document.
- // If found, it brings the document to the front. If not, it asks the
- // current debugger (who filled in the list) to fetch the script.
-
- window.scripts.output.onChange = function()
- {
- if (this.selection && this.selection.text.length)
- {
- var info = this.selection.info;
- if (info)
- {
- var scriptID = info.scriptID;
- var doc = documents.find (scriptID);
- if (doc)
- document = doc;
- else
- this.parent.loadScript (scriptID, this.selection.text);
- }
- }
- }
-